package com.cdtu.stocksage.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdtu.stocksage.common.annotation.Log;
import com.cdtu.stocksage.common.core.controller.BaseController;
import com.cdtu.stocksage.common.core.domain.AjaxResult;
import com.cdtu.stocksage.common.enums.BusinessType;
import com.cdtu.stocksage.goods.domain.ErsGoodsEnterRecord;
import com.cdtu.stocksage.goods.service.IErsGoodsEnterRecordService;
import com.cdtu.stocksage.common.utils.poi.ExcelUtil;
import com.cdtu.stocksage.common.core.page.TableDataInfo;

/**
 * 物资入库记录Controller
 * 
 * @author SL
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/goods/inrecord")
public class ErsGoodsEnterRecordController extends BaseController
{
    @Autowired
    private IErsGoodsEnterRecordService ersGoodsEnterRecordService;

    /**
     * 查询物资入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('goods:inrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErsGoodsEnterRecord ersGoodsEnterRecord)
    {
        startPage();
        List<ErsGoodsEnterRecord> list = ersGoodsEnterRecordService.selectErsGoodsEnterRecordList(ersGoodsEnterRecord);
        return getDataTable(list);
    }

    /**
     * 导出物资入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('goods:inrecord:export')")
    @Log(title = "物资入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErsGoodsEnterRecord ersGoodsEnterRecord)
    {
        List<ErsGoodsEnterRecord> list = ersGoodsEnterRecordService.selectErsGoodsEnterRecordList(ersGoodsEnterRecord);
        ExcelUtil<ErsGoodsEnterRecord> util = new ExcelUtil<ErsGoodsEnterRecord>(ErsGoodsEnterRecord.class);
        util.exportExcel(response, list, "物资入库记录数据");
    }

    /**
     * 获取物资入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:inrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ersGoodsEnterRecordService.selectErsGoodsEnterRecordById(id));
    }

    /**
     * 新增物资入库记录
     */
    @PreAuthorize("@ss.hasPermi('goods:inrecord:add')")
    @Log(title = "物资入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErsGoodsEnterRecord ersGoodsEnterRecord)
    {
        return toAjax(ersGoodsEnterRecordService.insertErsGoodsEnterRecord(ersGoodsEnterRecord));
    }

    /**
     * 修改物资入库记录
     */
    @PreAuthorize("@ss.hasPermi('goods:inrecord:edit')")
    @Log(title = "物资入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErsGoodsEnterRecord ersGoodsEnterRecord)
    {
        return toAjax(ersGoodsEnterRecordService.updateErsGoodsEnterRecord(ersGoodsEnterRecord));
    }

    /**
     * 删除物资入库记录
     */
    @PreAuthorize("@ss.hasPermi('goods:inrecord:remove')")
    @Log(title = "物资入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ersGoodsEnterRecordService.deleteErsGoodsEnterRecordByIds(ids));
    }
}
